package design.p3_singleton;

/**
 * @ClassName: Java
 * @description: 方法分离
 * @author: zxf
 * @create: 2021-06-17 17:43
 **/
public class Singleton2 {

    private static Singleton2 instance = null;

    private Singleton2(){}

    private static synchronized void syncInit(){
        if (instance == null) instance = new Singleton2();
    }

    public static Singleton2 getInstance(){
        if (instance == null) syncInit();
        return instance;
    }
}

// 只会在第一次初始化实例加锁，不影响性能。

